using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace Thinxoft.XedusLive
{
    partial class Start
    {
        static RegistryKey software = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("software", true);

        internal static RegistryKey XedusKey
        {
            get
            {
                return software.OpenSubKey("xedus", true);
            }
        }

        static void DeleteXedusKey()
        {
            software.DeleteSubKey("xedus", false);
        }

        internal static void CreateXedusKey()
        {
            RegistryKey key = software.CreateSubKey("xedus");
            key.SetValue("usagecount", 30);
            key.SetValue("identity", new Guid().ToString());
            key.SetValue("activated", "false");
        }

        public static string Identity
        {
            get
            {
                try
                {
                    string id = (string)XedusKey.GetValue("identity");
                    return id;
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("The system may have been critically damaged.   Please check even log and if problem persists, uninstall and reinstall Xedus.");
                    Start.Log("{0}{1}", ex.Message, ex.StackTrace);
                    System.Windows.Forms.Application.Exit();
                    return null;
                }
            }
        }

        internal static bool Activated
        {
            get
            {
                try
                {
                    bool activated = (bool)XedusKey.GetValue("activated");
                    return activated;
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("The system may have been critically damaged.   Please check even log and if problem persists, uninstall and reinstall Xedus.");
                    Start.Log("{0}{1}", ex.Message, ex.StackTrace);
                    System.Windows.Forms.Application.Exit();
                    return false;
                }
            }
        }

        internal static int UsageCount
        {
            get
            {
                try
                {
                    int usagecount = (int)XedusKey.GetValue("usagecount");
                    return usagecount;
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("The system may have been critically damaged.  Please check even log and if problem persists, uninstall and reinstall Xedus.");
                    Start.Log("{0}{1}", ex.Message, ex.StackTrace);
                    System.Windows.Forms.Application.Exit();
                    return -1;
                }                

            }
        }

    }
}
